
using System;
using UnityEngine;
using WooEngine.UI.Interfaces;


namespace WooEngine.UI.Base
{
    public abstract class AbstractUIElement<T> : AbstractUIComponent<T>, IUIElement
    {
        public int SiblingIndex { get; private set; }

        public string ElementName => m_name;

        public virtual void EnableSwitch(bool isOn)
        {
            this.m_go.SetActive(isOn);
        }

        public void FadeIn(Action<string, GameObject> OnFadeInFinish = null)
        {
            void OnFadeInAnimFinish(string _pageName, GameObject _go)
            {
                if (OnFadeInFinish != null)
                {
                    OnFadeInFinish(_pageName, _go);
                }
                onPageShowOver();
            }
            this.FadeInAnim(OnFadeInAnimFinish);
        }

        public void FadeInAnim(Action<string, GameObject> OnFadeInAnimFinish = null)
        {
            if (OnFadeInAnimFinish != null)
            {
                OnFadeInAnimFinish(m_name, m_go);
            }
        }

        public virtual void FadeOut(Action<string, GameObject> OnFadeOutFinish = null)
        {
            TouchSwitch(false);

            void OnFadeOutAnimFinish(string _pageName, GameObject _go)
            {
                if (OnFadeOutFinish != null)
                {
                    OnFadeOutFinish(_pageName, _go);
                }
                onExit();
            }
            this.FadeOutAnim(OnFadeOutAnimFinish);
        }

        public void FadeOutAnim(Action<string, GameObject> OnFadeOutAnimFinish = null)
        {
            if (OnFadeOutAnimFinish != null)
            {
                OnFadeOutAnimFinish(m_name, m_go);
            }
        }



        protected virtual void onPageShowOver()
        {

        }

        protected virtual void onExit()
        {
        }


        public abstract void Release();

        public void SetSiblingIndex(int index)
        {
            SiblingIndex = index;
        }

        public abstract void TouchSwitch(bool isOn);

    }

}